package org.zjut.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zjut.db.LearnerKnowledgeAttrDataBase;
import org.zjut.db.RcommondDataBase;
import org.zjut.util.CommonUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Rising
 * @date 2017/9/23
 * @des 学习者对应知识点的属性操作
 */
@Controller
public class LeanerKnowledgeAttrController {
    @Autowired
    LearnerKnowledgeAttrDataBase learnerKnowledgeAttrDataBase;

    @Autowired
    RcommondDataBase mRecommondDataBase;
    /**
     * 存储用户对某个课程下面知识点关联能力值
     * @param request
     * @return
     */
    @RequestMapping(value = "/addUserKnowledgeAttr", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String addUserKnowledgeAttr(HttpServletRequest request){
        JSONObject params =null;
        if(request==null){
            return JSON.toJSONString(CommonUtil.setErrorInfo("请求参数有问题，请注意检查"));
        }else{
            params = JSON.parseObject(CommonUtil.getBodyRequest(request));
        }
        try {
            return JSON.toJSONString(learnerKnowledgeAttrDataBase.addKnowledgeAttr(params));
        } catch (Exception e) {
            return JSON.toJSONString(CommonUtil.setErrorInfo("生成失败"));
        }
    }

    @RequestMapping(value = "/getRecomondResource", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getRecomondResource(HttpServletRequest request){
        JSONObject params =null;
        if(request==null){
            return JSON.toJSONString(CommonUtil.setErrorInfo("请求参数有问题，请注意检查"));
        }else{
            params = JSON.parseObject(CommonUtil.getBodyRequest(request));
        }
        try {
            return JSON.toJSONString(mRecommondDataBase.recommondResource(params));
        } catch (Exception e) {
            return JSON.toJSONString(CommonUtil.setErrorInfo("获取失败"));
        }
    }

}
